package com.xkdx.guangguang.fragment.brand.photo;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.Photo;
import com.xkdx.guangguang.shareclass.PhotoAlbum;

public class BrandPhotosModule extends AbsModule {
	public PhotoAlbum photoAlbum;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getPhotoListByBrandAll")) {
					photoAlbum = parseShopPhotoAlbum(jsonObj
							.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	private PhotoAlbum parseShopPhotoAlbum(JSONObject person) throws Exception {
		PhotoAlbum photoAlbum = new PhotoAlbum();
		try {
			if (person == null) {
				return photoAlbum;
			}
			List<Photo> list = new ArrayList<Photo>();
			JSONObject stut = (JSONObject) person.get("Result");

			if (stut.has("DetailInfo")) {
				JSONObject data = (JSONObject) stut.get("DetailInfo");
				photoAlbum.setDataCount(data.getString("DataCount"));
				photoAlbum.setRefreshTime(data.getString("RefreshTime"));
			}

			if (stut.has("ListInfo")) {
				JSONArray jsonArray = (JSONArray) stut.getJSONArray("ListInfo");
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject item = (JSONObject) jsonArray.opt(i);
					Photo photo = new Photo();
					photo.setPhotoID(item.getString("PhotoID"));
					photo.setPhotoTitle(item.getString("PhotoTitle"));
					photo.setPhotoUrl(item.getString("PhotoUrl"));
					photo.setCommentCount(item.getString("CommentCount"));
					photo.setGalleryName(item.getString("GalleryName"));
					photo.setPrice(item.getString("Price"));
					photo.setRank(item.getString("Rank"));
					photo.setUserAvatars(item.getString("UserAvatars"));
					photo.setUserID(item.getString("UserID"));
					photo.setUserNickName(item.getString("UserNickName"));
					photo.setCreateTime(item.getString("CreateTime"));
					photo.setVerifyStatus(item.getString("VerifyStatus"));

					list.add(photo);
				}
			}
			photoAlbum.setList(list);

		} catch (Exception e) {
			throw e;
		}
		return photoAlbum;
	}

}
